#!/usr/bin/python

import urllib,urllib2,re
import xbmc,xbmcplugin,xbmcgui,sys

def GET_HTTP(url):
  req = urllib2.Request(url)
  req.add_header('User-Agent','Mozilla/5.0 (Windows NT 5.1; rv:8.0) Gecko/20100101 Firefox/8.0')
  req.add_header('Referer', 'http://beeg.com/')
  response = urllib2.urlopen(req)
  html=response.read()
  response.close()
  return html

def LIST_SECTIONS():
  addDir('18','http://beeg.com/tag/18',2,'')
  addDir('20','http://beeg.com/tag/20',2,'')
  addDir('30','http://beeg.com/tag/30',2,'')
  addDir('40','http://beeg.com/tag/40',2,'')
  addDir('50','http://beeg.com/tag/50',2,'')
  addDir('69','http://beeg.com/tag/69',2,'')
  addDir('Abuse','http://beeg.com/tag/abuse',2,'')
  addDir('Aggressive','http://beeg.com/tag/aggressive',2,'')
  addDir('Amateur','http://beeg.com/tag/amateur',2,'')
  addDir('Amazing','http://beeg.com/tag/amazing',2,'')
  addDir('American','http://beeg.com/tag/american',2,'')
  addDir('Anal','http://beeg.com/tag/anal',2,'')
  addDir('Anal dildo','http://beeg.com/tag/anal+dildo',2,'')
  addDir('Anal fingering','http://beeg.com/tag/anal+fingering',2,'')
  addDir('Anal fisting','http://beeg.com/tag/anal+fisting',2,'')
  addDir('Arab','http://beeg.com/tag/arab',2,'')
  addDir('Army','http://beeg.com/tag/army',2,'')
  addDir('Asian','http://beeg.com/tag/asian',2,'')
  addDir('Ass','http://beeg.com/tag/ass',2,'')
  addDir('Ass lick','http://beeg.com/tag/ass+lick',2,'')
  addDir('At work','http://beeg.com/tag/at+work',2,'')
  addDir('Babe','http://beeg.com/tag/babe',2,'')
  addDir('Bath','http://beeg.com/tag/bath',2,'')
  addDir('Bathroom','http://beeg.com/tag/bathroom',2,'')
  addDir('Bdsm','http://beeg.com/tag/bdsm',2,'')
  addDir('Beach','http://beeg.com/tag/beach',2,'')
  addDir('Beautiful','http://beeg.com/tag/beautiful',2,'')
  addDir('Beautiful ass','http://beeg.com/tag/beautiful+ass',2,'')
  addDir('Beautiful body','http://beeg.com/tag/beautiful+body',2,'')
  addDir('Beautiful face','http://beeg.com/tag/beautiful+face',2,'')
  addDir('Beautiful legs','http://beeg.com/tag/beautiful+legs',2,'')
  addDir('Beautiful tits','http://beeg.com/tag/beautiful+tits',2,'')
  addDir('Bed','http://beeg.com/tag/bed',2,'')
  addDir('Bedroom','http://beeg.com/tag/bedroom',2,'')
  addDir('Bend over','http://beeg.com/tag/bend+over',2,'')
  addDir('Big ass','http://beeg.com/tag/big+ass',2,'')
  addDir('Big cock','http://beeg.com/tag/big+cock',2,'')
  addDir('Big tits','http://beeg.com/tag/big+tits',2,'')
  addDir('Bikini','http://beeg.com/tag/bikini',2,'')
  addDir('Bisexual','http://beeg.com/tag/bisexual',2,'')
  addDir('Black','http://beeg.com/tag/black',2,'')
  addDir('Black cock','http://beeg.com/tag/black+cock',2,'')
  addDir('Blonde','http://beeg.com/tag/blonde',2,'')
  addDir('Blowjob','http://beeg.com/tag/blowjob',2,'')
  addDir('Blue eyes','http://beeg.com/tag/blue+eyes',2,'')
  addDir('Bondage','http://beeg.com/tag/bondage',2,'')
  addDir('Boots','http://beeg.com/tag/boots',2,'')
  addDir('Brazilian','http://beeg.com/tag/brazilian',2,'')
  addDir('Bride','http://beeg.com/tag/bride',2,'')
  addDir('British','http://beeg.com/tag/british',2,'')
  addDir('Brunette','http://beeg.com/tag/brunette',2,'')
  addDir('Brutal','http://beeg.com/tag/brutal',2,'')
  addDir('Brutal dildo','http://beeg.com/tag/brutal+dildo',2,'')
  addDir('Bukkake','http://beeg.com/tag/bukkake',2,'')
  addDir('Busty teen','http://beeg.com/tag/busty+teen',2,'')
  addDir('Campus','http://beeg.com/tag/campus',2,'')
  addDir('Car','http://beeg.com/tag/car',2,'')
  addDir('Cash','http://beeg.com/tag/cash',2,'')
  addDir('Casting','http://beeg.com/tag/casting',2,'')
  addDir('Cfnm','http://beeg.com/tag/cfnm',2,'')
  addDir('Chair','http://beeg.com/tag/chair',2,'')
  addDir('Cheat','http://beeg.com/tag/cheat',2,'')
  addDir('Cheerleader','http://beeg.com/tag/cheerleader',2,'')
  addDir('Class','http://beeg.com/tag/class',2,'')
  addDir('Classic','http://beeg.com/tag/classic',2,'')
  addDir('Classroom','http://beeg.com/tag/classroom',2,'')
  addDir('Closeup','http://beeg.com/tag/closeup',2,'')
  addDir('Clothes off','http://beeg.com/tag/clothes+off',2,'')
  addDir('Club','http://beeg.com/tag/club',2,'')
  addDir('Cock ride','http://beeg.com/tag/cock+ride',2,'')
  addDir('Coed','http://beeg.com/tag/coed',2,'')
  addDir('College girl','http://beeg.com/tag/college+girl',2,'')
  addDir('Compassionate','http://beeg.com/tag/compassionate',2,'')
  addDir('Couple','http://beeg.com/tag/couple',2,'')
  addDir('Creampie','http://beeg.com/tag/creampie',2,'')
  addDir('Cumshot','http://beeg.com/tag/cumshot',2,'')
  addDir('Curly','http://beeg.com/tag/curly',2,'')
  addDir('Cute','http://beeg.com/tag/cute',2,'')
  addDir('Czech','http://beeg.com/tag/czech',2,'')
  addDir('Dancing','http://beeg.com/tag/dancing',2,'')
  addDir('Dark','http://beeg.com/tag/dark',2,'')
  addDir('Decorations','http://beeg.com/tag/decorations',2,'')
  addDir('Deep throat','http://beeg.com/tag/deep+throat',2,'')
  addDir('Desk','http://beeg.com/tag/desk',2,'')
  addDir('Dildo','http://beeg.com/tag/dildo',2,'')
  addDir('Dirty talk','http://beeg.com/tag/dirty+talk',2,'')
  addDir('Doctor','http://beeg.com/tag/doctor',2,'')
  addDir('Doggy','http://beeg.com/tag/doggy',2,'')
  addDir('Domination','http://beeg.com/tag/domination',2,'')
  addDir('Dorm','http://beeg.com/tag/dorm',2,'')
  addDir('Double','http://beeg.com/tag/double',2,'')
  addDir('Dress','http://beeg.com/tag/dress',2,'')
  addDir('Drunk','http://beeg.com/tag/drunk',2,'')
  addDir('Ebony','http://beeg.com/tag/ebony',2,'')
  addDir('Education','http://beeg.com/tag/education',2,'')
  addDir('Emotional','http://beeg.com/tag/emotional',2,'')
  addDir('Erotic','http://beeg.com/tag/erotic',2,'')
  addDir('European','http://beeg.com/tag/european',2,'')
  addDir('Extreme','http://beeg.com/tag/extreme',2,'')
  addDir('Eyes','http://beeg.com/tag/eyes',2,'')
  addDir('Face','http://beeg.com/tag/face',2,'')
  addDir('Facesitting','http://beeg.com/tag/facesitting',2,'')
  addDir('Facial','http://beeg.com/tag/facial',2,'')
  addDir('Family','http://beeg.com/tag/family',2,'')
  addDir('Fashionable','http://beeg.com/tag/fashionable',2,'')
  addDir('Fat cock','http://beeg.com/tag/fat+cock',2,'')
  addDir('Feet','http://beeg.com/tag/feet',2,'')
  addDir('Female teacher','http://beeg.com/tag/female+teacher',2,'')
  addDir('Femdom','http://beeg.com/tag/femdom',2,'')
  addDir('Fetish','http://beeg.com/tag/fetish',2,'')
  addDir('Fffm','http://beeg.com/tag/fffm',2,'')
  addDir('Ffm','http://beeg.com/tag/ffm',2,'')
  addDir('Ffmm','http://beeg.com/tag/ffmm',2,'')
  addDir('Finger fuck','http://beeg.com/tag/finger+fuck',2,'')
  addDir('Fingering','http://beeg.com/tag/fingering',2,'')
  addDir('Fisting','http://beeg.com/tag/fisting',2,'')
  addDir('Flexible','http://beeg.com/tag/flexible',2,'')
  addDir('Flirty','http://beeg.com/tag/flirty',2,'')
  addDir('Floor','http://beeg.com/tag/floor',2,'')
  addDir('Fmm','http://beeg.com/tag/fmm',2,'')
  addDir('Fmmm','http://beeg.com/tag/fmmm',2,'')
  addDir('Food','http://beeg.com/tag/food',2,'')
  addDir('Foot','http://beeg.com/tag/foot',2,'')
  addDir('Footjob','http://beeg.com/tag/footjob',2,'')
  addDir('French','http://beeg.com/tag/french',2,'')
  addDir('Fresh','http://beeg.com/tag/fresh',2,'')
  addDir('From behind','http://beeg.com/tag/from+behind',2,'')
  addDir('Fucking','http://beeg.com/tag/fucking',2,'')
  addDir('Fun','http://beeg.com/tag/fun',2,'')
  addDir('Gangbang','http://beeg.com/tag/gangbang',2,'')
  addDir('German','http://beeg.com/tag/german',2,'')
  addDir('Girlfriend','http://beeg.com/tag/girlfriend',2,'')
  addDir('Glamour','http://beeg.com/tag/glamour',2,'')
  addDir('Glasses','http://beeg.com/tag/glasses',2,'')
  addDir('Glory hole','http://beeg.com/tag/glory+hole',2,'')
  addDir('Good cock','http://beeg.com/tag/good+cock',2,'')
  addDir('Gorgeous','http://beeg.com/tag/gorgeous',2,'')
  addDir('Granny','http://beeg.com/tag/granny',2,'')
  addDir('Green eyes','http://beeg.com/tag/green+eyes',2,'')
  addDir('Grey eyes','http://beeg.com/tag/grey+eyes',2,'')
  addDir('Group','http://beeg.com/tag/group',2,'')
  addDir('Hairstyle','http://beeg.com/tag/hairstyle',2,'')
  addDir('Hairy','http://beeg.com/tag/hairy',2,'')
  addDir('Handcuffs','http://beeg.com/tag/handcuffs',2,'')
  addDir('Handjob','http://beeg.com/tag/handjob',2,'')
  addDir('Hardcore','http://beeg.com/tag/hardcore',2,'')
  addDir('Harder','http://beeg.com/tag/harder',2,'')
  addDir('Heels','http://beeg.com/tag/heels',2,'')
  addDir('Hidden cam','http://beeg.com/tag/hidden+cam',2,'')
  addDir('Home video','http://beeg.com/tag/home+video',2,'')
  addDir('Homemade','http://beeg.com/tag/homemade',2,'')
  addDir('Horny','http://beeg.com/tag/horny',2,'')
  addDir('Hospital','http://beeg.com/tag/hospital',2,'')
  addDir('Hotel','http://beeg.com/tag/hotel',2,'')
  addDir('Housewife','http://beeg.com/tag/housewife',2,'')
  addDir('Humiliation','http://beeg.com/tag/humiliation',2,'')
  addDir('Hungarian','http://beeg.com/tag/hungarian',2,'')
  addDir('In clothes','http://beeg.com/tag/in+clothes',2,'')
  addDir('In nature','http://beeg.com/tag/in+nature',2,'')
  addDir('Indian','http://beeg.com/tag/indian',2,'')
  addDir('Innocent','http://beeg.com/tag/innocent',2,'')
  addDir('Interracial','http://beeg.com/tag/interracial',2,'')
  addDir('Interview','http://beeg.com/tag/interview',2,'')
  addDir('Italian','http://beeg.com/tag/italian',2,'')
  addDir('Japanese','http://beeg.com/tag/japanese',2,'')
  addDir('Jeans','http://beeg.com/tag/jeans',2,'')
  addDir('Kiss','http://beeg.com/tag/kiss',2,'')
  addDir('Kitchen','http://beeg.com/tag/kitchen',2,'')
  addDir('Lady','http://beeg.com/tag/lady',2,'')
  addDir('Latex','http://beeg.com/tag/latex',2,'')
  addDir('Latin','http://beeg.com/tag/latin',2,'')
  addDir('Legs','http://beeg.com/tag/legs',2,'')
  addDir('Lesbian','http://beeg.com/tag/lesbian',2,'')
  addDir('Lesbian teen','http://beeg.com/tag/lesbian+teen',2,'')
  addDir('Lick','http://beeg.com/tag/lick',2,'')
  addDir('Lingerie','http://beeg.com/tag/lingerie',2,'')
  addDir('Location','http://beeg.com/tag/location',2,'')
  addDir('Long hair','http://beeg.com/tag/long+hair',2,'')
  addDir('Long legs','http://beeg.com/tag/long+legs',2,'')
  addDir('Long videos','http://beeg.com/tag/long+videos',2,'')
  addDir('Maid','http://beeg.com/tag/maid',2,'')
  addDir('Male strip','http://beeg.com/tag/male+strip',2,'')
  addDir('Male teacher','http://beeg.com/tag/male+teacher',2,'')
  addDir('Massage','http://beeg.com/tag/massage',2,'')
  addDir('Masturbation','http://beeg.com/tag/masturbation',2,'')
  addDir('Mature','http://beeg.com/tag/mature',2,'')
  addDir('Medical','http://beeg.com/tag/medical',2,'')
  addDir('Mexican','http://beeg.com/tag/mexican',2,'')
  addDir('Milf','http://beeg.com/tag/milf',2,'')
  addDir('Mini','http://beeg.com/tag/mini',2,'')
  addDir('Missionary','http://beeg.com/tag/missionary',2,'')
  addDir('Mistress','http://beeg.com/tag/mistress',2,'')
  addDir('Moan','http://beeg.com/tag/moan',2,'')
  addDir('Mom','http://beeg.com/tag/mom',2,'')
  addDir('Money','http://beeg.com/tag/money',2,'')
  addDir('Mother','http://beeg.com/tag/mother',2,'')
  addDir('Natural','http://beeg.com/tag/natural',2,'')
  addDir('Natural tits','http://beeg.com/tag/natural+tits',2,'')
  addDir('New face','http://beeg.com/tag/new+face',2,'')
  addDir('Nun','http://beeg.com/tag/nun',2,'')
  addDir('Nurse','http://beeg.com/tag/nurse',2,'')
  addDir('Nylon','http://beeg.com/tag/nylon',2,'')
  addDir('Observe','http://beeg.com/tag/observe',2,'')
  addDir('Office','http://beeg.com/tag/office',2,'')
  addDir('Office girl','http://beeg.com/tag/office+girl',2,'')
  addDir('Oiled','http://beeg.com/tag/oiled',2,'')
  addDir('Old/young','http://beeg.com/tag/old%2Fyoung',2,'')
  addDir('Old man','http://beeg.com/tag/old+man',2,'')
  addDir('On cam','http://beeg.com/tag/on+cam',2,'')
  addDir('Orgasm','http://beeg.com/tag/orgasm',2,'')
  addDir('Orgy','http://beeg.com/tag/orgy',2,'')
  addDir('Oriental','http://beeg.com/tag/oriental',2,'')
  addDir('Outdoor','http://beeg.com/tag/outdoor',2,'')
  addDir('Panties','http://beeg.com/tag/panties',2,'')
  addDir('Panties off','http://beeg.com/tag/panties+off',2,'')
  addDir('Pantyhose','http://beeg.com/tag/pantyhose',2,'')
  addDir('Park','http://beeg.com/tag/park',2,'')
  addDir('Party','http://beeg.com/tag/party',2,'')
  addDir('Patient','http://beeg.com/tag/patient',2,'')
  addDir('Peeing','http://beeg.com/tag/peeing',2,'')
  addDir('Penetration','http://beeg.com/tag/penetration',2,'')
  addDir('Perky tits','http://beeg.com/tag/perky+tits',2,'')
  addDir('Petite','http://beeg.com/tag/petite',2,'')
  addDir('Piercing','http://beeg.com/tag/piercing',2,'')
  addDir('Pigtails','http://beeg.com/tag/pigtails',2,'')
  addDir('Pink','http://beeg.com/tag/pink',2,'')
  addDir('Pissing','http://beeg.com/tag/pissing',2,'')
  addDir('Plump','http://beeg.com/tag/plump',2,'')
  addDir('Pool','http://beeg.com/tag/pool',2,'')
  addDir('Pornstar','http://beeg.com/tag/pornstar',2,'')
  addDir('Posing','http://beeg.com/tag/posing',2,'')
  addDir('Pov','http://beeg.com/tag/pov',2,'')
  addDir('Pregnant','http://beeg.com/tag/pregnant',2,'')
  addDir('Pretty','http://beeg.com/tag/pretty',2,'')
  addDir('Public','http://beeg.com/tag/public',2,'')
  addDir('Punishment','http://beeg.com/tag/punishment',2,'')
  addDir('Pussy','http://beeg.com/tag/pussy',2,'')
  addDir('Pussy cumshot','http://beeg.com/tag/pussy+cumshot',2,'')
  addDir('Quickie','http://beeg.com/tag/quickie',2,'')
  addDir('Rare face','http://beeg.com/tag/rare+face',2,'')
  addDir('Rare position','http://beeg.com/tag/rare+position',2,'')
  addDir('Reality','http://beeg.com/tag/reality',2,'')
  addDir('Redhead','http://beeg.com/tag/redhead',2,'')
  addDir('Retro','http://beeg.com/tag/retro',2,'')
  addDir('Role','http://beeg.com/tag/role',2,'')
  addDir('Romantic','http://beeg.com/tag/romantic',2,'')
  addDir('Rough sex','http://beeg.com/tag/rough+sex',2,'')
  addDir('Russian','http://beeg.com/tag/russian',2,'')
  addDir('Scene','http://beeg.com/tag/scene',2,'')
  addDir('School','http://beeg.com/tag/school',2,'')
  addDir('Schoolgirl','http://beeg.com/tag/schoolgirl',2,'')
  addDir('Scream','http://beeg.com/tag/scream',2,'')
  addDir('Secretary','http://beeg.com/tag/secretary',2,'')
  addDir('Seduction','http://beeg.com/tag/seduction',2,'')
  addDir('Sex','http://beeg.com/tag/sex',2,'')
  addDir('Shaved','http://beeg.com/tag/shaved',2,'')
  addDir('Shaving','http://beeg.com/tag/shaving',2,'')
  addDir('Shemale','http://beeg.com/tag/shemale',2,'')
  addDir('Short hose','http://beeg.com/tag/short+hose',2,'')
  addDir('Shower','http://beeg.com/tag/shower',2,'')
  addDir('Showing off','http://beeg.com/tag/showing+off',2,'')
  addDir('Shy','http://beeg.com/tag/shy',2,'')
  addDir('Sister','http://beeg.com/tag/sister',2,'')
  addDir('Skinny','http://beeg.com/tag/skinny',2,'')
  addDir('Skirt','http://beeg.com/tag/skirt',2,'')
  addDir('Slave','http://beeg.com/tag/slave',2,'')
  addDir('Sleep','http://beeg.com/tag/sleep',2,'')
  addDir('Slow','http://beeg.com/tag/slow',2,'')
  addDir('Small tits','http://beeg.com/tag/small+tits',2,'')
  addDir('Smoke','http://beeg.com/tag/smoke',2,'')
  addDir('Socks','http://beeg.com/tag/socks',2,'')
  addDir('Sofa','http://beeg.com/tag/sofa',2,'')
  addDir('Solo','http://beeg.com/tag/solo',2,'')
  addDir('Spanish','http://beeg.com/tag/spanish',2,'')
  addDir('Spanking','http://beeg.com/tag/spanking',2,'')
  addDir('Spontaneous','http://beeg.com/tag/spontaneous',2,'')
  addDir('Sporty','http://beeg.com/tag/sporty',2,'')
  addDir('Spreading','http://beeg.com/tag/spreading',2,'')
  addDir('Squirt','http://beeg.com/tag/squirt',2,'')
  addDir('Standing position','http://beeg.com/tag/standing+position',2,'')
  addDir('Starlet','http://beeg.com/tag/starlet',2,'')
  addDir('Step-daughter','http://beeg.com/tag/step-daughter',2,'')
  addDir('Step-mom','http://beeg.com/tag/step-mom',2,'')
  addDir('Stockings','http://beeg.com/tag/stockings',2,'')
  addDir('Strapon','http://beeg.com/tag/strapon',2,'')
  addDir('Stretching','http://beeg.com/tag/stretching',2,'')
  addDir('Strip','http://beeg.com/tag/strip',2,'')
  addDir('Student','http://beeg.com/tag/student',2,'')
  addDir('Stupid','http://beeg.com/tag/stupid',2,'')
  addDir('Stylish','http://beeg.com/tag/stylish',2,'')
  addDir('Submissive','http://beeg.com/tag/submissive',2,'')
  addDir('Swallow','http://beeg.com/tag/swallow',2,'')
  addDir('Swedish','http://beeg.com/tag/swedish',2,'')
  addDir('Sweet','http://beeg.com/tag/sweet',2,'')
  addDir('Swinger','http://beeg.com/tag/swinger',2,'')
  addDir('Table','http://beeg.com/tag/table',2,'')
  addDir('Tall','http://beeg.com/tag/tall',2,'')
  addDir('Tanned','http://beeg.com/tag/tanned',2,'')
  addDir('Tattoo','http://beeg.com/tag/tattoo',2,'')
  addDir('Teacher','http://beeg.com/tag/teacher',2,'')
  addDir('Tease','http://beeg.com/tag/tease',2,'')
  addDir('Teen','http://beeg.com/tag/teen',2,'')
  addDir('Teen anal','http://beeg.com/tag/teen+anal',2,'')
  addDir('Teen hardcore','http://beeg.com/tag/teen+hardcore',2,'')
  addDir('Teen sex','http://beeg.com/tag/teen+sex',2,'')
  addDir('Threesome','http://beeg.com/tag/threesome',2,'')
  addDir('Tied','http://beeg.com/tag/tied',2,'')
  addDir('Tight','http://beeg.com/tag/tight',2,'')
  addDir('Tight body','http://beeg.com/tag/tight+body',2,'')
  addDir('Tits cumshot','http://beeg.com/tag/tits+cumshot',2,'')
  addDir('Tits fuck','http://beeg.com/tag/tits+fuck',2,'')
  addDir('Toilet','http://beeg.com/tag/toilet',2,'')
  addDir('Toy','http://beeg.com/tag/toy',2,'')
  addDir('Transexual','http://beeg.com/tag/transexual',2,'')
  addDir('Turkish','http://beeg.com/tag/turkish',2,'')
  addDir('Undressing','http://beeg.com/tag/undressing',2,'')
  addDir('Uniform','http://beeg.com/tag/uniform',2,'')
  addDir('Unusual','http://beeg.com/tag/unusual',2,'')
  addDir('Upskirt','http://beeg.com/tag/upskirt',2,'')
  addDir('Vintage','http://beeg.com/tag/vintage',2,'')
  addDir('Virgin','http://beeg.com/tag/virgin',2,'')
  addDir('Voyeur','http://beeg.com/tag/voyeur',2,'')
  addDir('Wet','http://beeg.com/tag/wet',2,'')
  addDir('White','http://beeg.com/tag/white',2,'')
  addDir('Wife','http://beeg.com/tag/wife',2,'')
  addDir('Young','http://beeg.com/tag/young',2,'')
  addDir('Young/old','http://beeg.com/tag/young%2Fold',2,'')
  addDir('Young couple','http://beeg.com/tag/young+couple',2,'')

def LIST_ITEMS(url):
  html = GET_HTTP(url)
  i = re.search('var tumbid  =(.+?);', html)
  d = re.search('var tumbalt =(.+?)\];', html)

  ids = i.group(1)
  ids = ids[1:-1]
  idlist = ids.split(',')
  inum = len(idlist)

  descs = d.group(1)
  descs = descs[2:-2]
  descs = descs.decode('string_escape')
  desclist =  descs.split("','")
  dnum = len(desclist)

  for x in range(0, inum):
    title = desclist[x]
    url = 'http://beeg.com/' + idlist[x]
    image = 'http://cdn.anythumb.com/236x177/' + idlist[x] + '.jpg'
    addDownLink(title,url,3,image)

  n = re.search('<a href="(.+?)" target="_self" id="paging_next">', html)
  if n:
    next = n.group(1)
    addDir(' Next Page',next,2,'')

def HOME():
  html = GET_HTTP('http://beeg.com/section/home/')
  addDir(' Categories','http://beeg.com/',1,'')

  i = re.search('var tumbid  =(.+?);', html)
  d = re.search('var tumbalt =(.+?)\];', html)

  ids = i.group(1)
  ids = ids[1:-1]
  idlist = ids.split(',')  
  inum = len(idlist)

  descs = d.group(1)
  descs = descs[2:-2]
  descs = descs.decode('string_escape')
  desclist =  descs.split("','")
  dnum = len(desclist)

  for x in range(0, inum):
    title = desclist[x]
    url = 'http://beeg.com/' + idlist[x]
    image = 'http://cdn.anythumb.com/236x177/' + idlist[x] + '.jpg'
    addDownLink(title,url,3,image)

  n = re.search('<a href="(.+?)" target="_self" id="paging_next">', html)
  if n:
    next = n.group(1)
    addDir(' Next Page',next,2,'')

def VIDEOLINKS(url,title):
  html = GET_HTTP(url)
  match=re.compile("'file': '(.+?)'").findall(html)
  for link in match:
    print 'Link: ' + link
    listitem = xbmcgui.ListItem(title)
    listitem.setInfo('video', {'Title': title})
    xbmc.Player( xbmc.PLAYER_CORE_DVDPLAYER ).play( str(link), listitem)

def get_params():
  param=[]
  paramstring=sys.argv[2]
  if len(paramstring)>=2:
    params=sys.argv[2]
    cleanedparams=params.replace('?','')
    if (params[len(params)-1]=='/'):
      params=params[0:len(params)-2]
    pairsofparams=cleanedparams.split('&')
    param={}
    for i in range(len(pairsofparams)):
      splitparams={}
      splitparams=pairsofparams[i].split('=')
      if (len(splitparams))==2:
        param[splitparams[0]]=splitparams[1]
  return param

def addDir(name,url,mode,iconimage):
  u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
  ok=True
  liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png",thumbnailImage=iconimage)
  liz.setInfo( type="Video", infoLabels={ "Title": name })
  ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  return ok

def addDownLink(name,url,mode,iconimage):
  u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
  ok=True
  liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  liz.setInfo( type="Video", infoLabels={ "Title": name } )
  ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
  return ok

params=get_params()
url=None
name=None
mode=None

try:
  url=urllib.unquote_plus(params["url"])
except:
  pass
try:
  name=urllib.unquote_plus(params["name"])
except:
  pass
try:
  mode=int(params["mode"])
except:
  pass

print 'Mode: ' + str(mode)
print 'URL : ' + str(url)
print 'Name: ' + str(name)

if mode==None or url==None or len(url)<1:
  HOME()
elif mode==1:
  LIST_SECTIONS()
elif mode==2:
  LIST_ITEMS(url)
elif mode==3:
  VIDEOLINKS(url,name)

xbmcplugin.endOfDirectory(int(sys.argv[1]))
